{aide_template 'common/header'}
<link href="{$aideUrl}web/resource/css/util.min.css" rel="stylesheet">
<script type="text/javascript" src="{$aideUrl}web/resource/js/util.min.js?v=20170912"></script>
<ul class="nav nav-tabs">
	<li {if $operation == 'display'} class="active" {/if}><a href="{php echo web_url('store/adv',array('op' =>'display'))}">轮播图</a></li>
	<li{if empty($adv['id']) && $operation == 'post'} class="active" {/if}><a href="{php echo web_url('store/adv',array('op' =>'post'))}">添加轮播图</a></li>
	{if !empty($adv['id']) &&  $operation == 'post'}<li  class="active"><a href="{php echo web_url('store/adv',array('op' =>'post','id'=>$adv['id']))}">编辑轮播图</a></li>{/if}
</ul>

{if $operation == 'display'}
<div class="main panel panel-default">
	<div class="table-responsive">
		<table class="table table-hover">
			<thead class="navbar-inner">
				<tr>
					<th style="width:15%;">图片</th>
					<th style="width:10%;">显示顺序</th>
					<th>标题</th>
					<th style="width:10%;">状态</th>
					<th class="text-right" style="width:15%;">操作</th>
				</tr>
			</thead>
			<tbody>
				{loop $list $adv}
				<tr>
					<td><img class="scrollLoading" src="{php echo tomedia($adv['thumb'])}" data-url="{php echo tomedia($adv['thumb'])}" onerror="this.src='{php echo tomedia($adv['thumb'])}'" height="50" width="100"/></td>
					<td>{$adv['displayorder']}</td>
					<td>{$adv['advname']}</td>
					<td>{if $adv['enabled'] == 0}<span class="label label-default">隐藏</span>{/if}
						{if $adv['enabled'] == 1}<span class="label label-success">显示</span>{/if}</td>
					<td class="text-right">
						<a href="{php echo web_url('store/adv', array('op' => 'post', 'id' => $adv['id']))}" class="btn btn-default btn-sm" data-toggle="tooltip" data-placement="top" title="修改"><i class="fa fa-edit"></i></a>
						<a href="{php echo web_url('store/adv', array('op' => 'delete', 'id' => $adv['id']))}"class="btn btn-default btn-sm" data-toggle="tooltip" data-placement="top" title="删除"><i class="fa fa-times"></i></a>
					</td>
				</tr>
				{/loop}
			</tbody>
		</table>
		{$pager}
	</div>
</div>
<script>
	require(['bootstrap'],function($){
		$('.btn').hover(function(){
			$(this).tooltip('show');
		},function(){
			$(this).tooltip('hide');
		});
	});
	$(function(){
		$(".scrollLoading").scrollLoading();
		var $pop = null;
		$('.scrollLoading').hover(function(){
			var img = $(this).attr('src');
			var obj = this;
			var $pop = util.popover(obj, function($popover, obj){
				obj.$popover = $popover;
			}, '<div><img src="'+img+'" style="max-width:200px; max-height:200px;"></div>');
		}, function(){
			this.$popover.remove();
		});
	});
</script>
{elseif $operation == 'post'}
<div class="main">
	<form action="" method="post" class="form-horizontal form" enctype="multipart/form-data" onsubmit='return formcheck()'>
		<input type="hidden" name="id" value="{$adv['id']}" />
		<div class="panel panel-default">
			<div class="panel-heading">
				轮播图设置
			</div>
			<div class="panel-body">
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">排序</label>
					<div class="col-sm-9 col-xs-12">
						<input type="text" name="displayorder" class="form-control" value="{$adv['displayorder']}" />
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">轮播图标题</label>
					<div class="col-sm-9 col-xs-12">
						<input type="text" id='advname' name="advname" class="form-control" value="{$adv['advname']}" placeholder='不填写标题不显示'/>
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">轮播图图片</label>
					<div class="col-sm-9 col-xs-12">
						{php echo tpl_form_field_image('thumb', $adv['thumb'])}
                        <div class="help-block">图片建议为：640*300</div>
					</div>
				</div>
				 <div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">轮播图连接</label>
					<div class="col-sm-9 col-xs-12">
						<select name="link" class="form-control">
							{loop $activity $value}
							<option value="{$value['link']}" {if $adv['link'] == $value['link']}selected{/if}>{$value['title']}</option>
							{/loop}
						</select>
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">是否显示</label>
					<div class="col-sm-9 col-xs-12">
						<label class='radio-inline'>
							<input type='radio' name='enabled' value='1' {if $adv['enabled']==1 || $adv['enabled']==''}checked{/if} /> 是
						</label>
						<label class='radio-inline'>
							<input type='radio' name='enabled' value='0' {if $adv['enabled']=='0'}checked{/if} /> 否
						</label>
					</div>
				</div>
			</div>
		</div>
<div class="form-group col-sm-12">
	<input type="submit" name="submit" value="提交" class="btn btn-primary col-lg-1" />
	<input type="hidden" name="token" value="{$_W['token']}" />
	</div>
	</form>
</div>

<script language='javascript'>
	function formcheck() {
		if ($("#advname").isEmpty()) {
			Tip.focus("advname", "请填写轮播图名称!");
			return false;
		}
		return true;
	}
</script>
{/if}
{aide_template 'common/footer'}
